﻿using Omniscient.Foundation.ApplicationModel.Modularity;
using Omniscient.Foundation;
using Omniscient.Foundation.ApplicationModel.Presentation;
using Omniscient.Foundation.ApplicationModel;
using Omniscient.Foundation.ApplicationModel.Security;

namespace Omniscient.TimeTracker.Security
{
    public class CredentialServiceModule : IModule, IStartable
    {
        #region IModule Members

        public IPresentationController PresentationController { get; set; }

        #endregion

        #region IStartable Members

        public void Start()
        {
            IExtensionPortManager manager;
            manager = ApplicationManager.Current.ExtensionPortManager;
            if (manager.GetExtensionPort<ICredentialServiceExtenderContract>() != null)
            {
                // Register extender for ICredentialServiceExtenderContract extention port
                CredentialServiceExtender extender = new CredentialServiceExtender(PresentationController);
                manager.GetExtensionPort<ICredentialServiceExtenderContract>().Register(extender);
            }
            // Authentify user
            ApplicationManager.Current.ServiceProvider.GetService<ICredentialService>().EnsureUserIsAuthenticated();
        }

        public void Stop()
        {
            throw new System.NotImplementedException();
        }

        #endregion
    }
}
